
module Foo where

import Data.Char
import System.Directory
import Monad
import FilePath

listDirs :: [FilePath] -> IO [FilePath]
listDirs = filterM doesDirectoryExist

listFiles :: [FilePath] -> IO [FilePath]
listFiles = filterM doesFileExist

isDotOrDoubleDot :: String -> Bool
isDotOrDoubleDot s =
    case s of
        "." -> True
        ".." -> True
        _ -> False

spider f path = do
    putStrLn path
    ls <- getDirectoryContents path
    let ls_filtered = filter (not . isDotOrDoubleDot) ls
    files <- listFiles ls_filtered
    dirs <- listDirs ls_filtered
    
    mapM f files
    let qualDirs = mapM (\x -> joinPath path x) dirs
    putStrLn (show qualDirs)
    mapM (\x -> spider f x) foo >>= return . concat

main = do
    cwd <- getCurrentDirectory
    spider putStrLn cwd
    
